//业务类
package service;

import dao.i.UserInfoDao;
import dao.impl.UserInfoDaoImpl;
import entity.UserInfo;
//用户相关的业务类

public class UserInfoService {

    UserInfoDao userInfoDao = new UserInfoDaoImpl();

    //用户注册
    public boolean UserRegister(String userName, String passWord, String nickName, int age, String sex) {
        UserInfo userInfo = new UserInfo();
        userInfo.setLevel(0);
        userInfo.setHead("http://127.0.0.1/a.jpg");
        userInfo.setUserName(userName);
        userInfo.setPassWord(passWord);
        userInfo.setNickName(nickName);
        userInfo.setAge(age);
        userInfo.setSex(sex);
        //保存到数据库
        this.userInfoDao.insertUserInfo(userInfo);

        return false;
    }

    //判断用户名和密码是否匹配
    public boolean checkPassWord(String userName, String passWord) {
        //按userName查找
        UserInfo userInfo = userInfoDao.selectUserInfoByUserName(userName);
        //找不到匹配失败
        if (userInfo == null) {
            return false;
        }
        //判断数据库的密码是否和传进来的密码相等
        return userInfo.getPassWord().equalsIgnoreCase(passWord);
    }

    //按userName获取一个UserInfo
    public UserInfo selectUserInfoByUserName(String userName) {
        return this.userInfoDao.selectUserInfoByUserName(userName);
    }

}
